﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using Peak.Core;

namespace Peak.Data.NHibernateMaps
{
  public class StoryMap : IAutoMappingOverride<Story>
  {
    public void Override(AutoMapping<Story> mapping)
    {
      mapping.Id(x => x.Id, "id").UnsavedValue(0).GeneratedBy.Identity();
      mapping.Map(x => x.Name).Not.Nullable();      
      mapping.Map(x => x.Category);
      mapping.Map(x => x.StartDate);
      mapping.Map(x => x.EndDate);
      mapping.Map(x => x.Created).Not.Nullable();
      mapping.Map(x => x.CreatedBy);
      mapping.Map(x => x.StartDate);
      mapping.Map(x => x.EndDate);
      mapping.Map(x => x.Requester);
      mapping.Map(x => x.Description);
      mapping.Map(x => x.Requester);
      mapping.Map(x => x.HowToDemo);
      mapping.Map(x => x.Priority).Not.Nullable().Default("0");
      mapping.Map(x => x.StoryPoints);
      mapping.Map(x => x.Status).CustomType(typeof(StoryStatus)).Not.Nullable().Default(((int)StoryStatus.ToDo).ToString()); ;
      mapping.References(x => x.Project);
      mapping.HasMany(x => x.SprintStories).Cascade.All();
      mapping.HasMany(x => x.Changes).Cascade.All();
    }
  }
}